package com.liugh.controller.zhongche;

import com.baomidou.mybatisplus.plugins.Page;
import com.liugh.config.ResponseModel;
import com.liugh.controller.BaseRestController;
import com.liugh.entity.standard.StandardItem;
import com.liugh.service.zhongche.ISearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Fatao on 2018/9/27
 */
@RestController
@RequestMapping("/search")
@Api(description = "搜索模块")
public class SearchController extends BaseRestController {


    @Autowired
    private ISearchService searchService;

    /**
     * 简单查询 .
     * @param standNo .
     * @param standName .
     * @return
     */

    @ApiOperation("简单查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "standNo", value = "标准编号",
                     required = false, dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "standName", value = "标准名称",
                     required = false, dataType = "String",paramType = "query")
    })
    @GetMapping("/simple")
    public ResponseModel<Page<StandardItem>> simpleSearch(@RequestParam(value = "standNo",required = false) String standNo,
                                      @RequestParam(value = "standName",required = false) String standName,
                                      @RequestParam(value = "pageNum",defaultValue = "1",required = false)int pageNum,
                                      @RequestParam(value = "pageSize",defaultValue = "10",required = false)int pageSize) {

        return fillSuccessDataPage(searchService.simpleSearch(standNo,standName,new Page<>(pageNum,pageSize)));
    }





    /**
     * 高级查询,根据标准名称模糊 .
     * @param key1 .
     * @param key2 .
     * @param key3 .
     * @param pageNum .
     * @param pageSize .
     * @return .
     */
    @ApiOperation("高级查询-名称模糊查询")
    @GetMapping("/complex-name")
    public ResponseModel<Page<StandardItem>> complexSearchByName(@RequestParam(value = "key1") String key1,
                                                                 @RequestParam(value = "key2",required = false) String key2,
                                                                 @RequestParam(value = "key3",required = false) String key3,
                                                                 @RequestParam(value = "pageNum",defaultValue = "1",required = false)int pageNum,
                                                                 @RequestParam(value = "pageSize",defaultValue = "10",required = false)int pageSize) {

        Page<StandardItem> itemPagelist = searchService.complexSearchByName(key1,key2,key3,new Page<>(pageNum,pageSize));
        return fillSuccessDataPage(itemPagelist);
    }


    @ApiOperation("全文检索")
    @GetMapping("/full_text")
//    @Cacheable(value = "full_text",keyGenerator = "wiselyKeyGenerator")
    public ResponseModel fullTextQuery(@RequestParam("key")String key,
                                       @RequestParam(value = "pageNum",required = false,defaultValue = "1")int pageNum,
                                       @RequestParam(value = "pageSize", required = false, defaultValue = "10")int pageSize) {
        Page page = new Page<>(pageNum,pageSize);
        page = searchService.fullTextQuery(page,key);
        return fillSuccessDataPage(page);
    }

}
